package cn.itcast.controller;

import cn.itcast.common.Result;
import cn.itcast.domain.Account;
import cn.itcast.domain.Good;
import cn.itcast.service.AccountService;
import cn.itcast.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.sound.midi.Soundbank;

import java.util.List;

@Controller
public class GoodsController {

    @Autowired
    private GoodService goodService;

    //查询所有数据
    @RequestMapping(value = "/good/goodList")
    @ResponseBody
    public Result findAll(HttpServletRequest request,String search) {
    	System.out.print(search);
        List<Good> accountList = goodService.findAll();
        request.setAttribute("accountList", accountList);
        return Result.createSuccess(accountList);
    }

    @RequestMapping(value = "/goodDetail")
    public String goodDetail(HttpServletRequest request,
                             @RequestParam("id") String id, Model m) {
        System.out.println(id);
        Good good = goodService.findById(Integer.valueOf(id));
        m.addAttribute("good",good);
        return "purchase";
    }

}
